package com.controller.kaoshi;

import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.model.Course;
import com.model.PaperConfig;
import com.model.Student;

import java.util.List;

/**
 * Created by Hexun on 2017/7/27 0027.
 */
public class ExamController extends Controller{
    /**
    *@Author:HeXun
    *@Description: 展示考试管理页面
    *@Date: 2017/7/27 0027
    */
    public void show(){
        List<Record> mujuanList= Db.find("select paperconfig.*,courses.name,courses.id as cid from paperconfig,courses where paperconfig.course_id=courses.id order by exam_time desc");
        setAttr("MujuanList",mujuanList);
        List<Record> examList=Db.find("select courses.name,paperconfig.exam_no,paperconfig.exam_time from paperconfig,courses where paperconfig.course_id =courses.id and paperconfig.exam_time != 0");
        setAttr("examList",examList);
        render("ExamManage.jsp");
    }

    /**
    *@Author:HeXun
    *@Description: 修改或添加考试时间
    *@Date: 2017/7/31 0031
    */
    public void updateTime(){
        int time=getParaToInt("time");
        int exam_no=getParaToInt("exam_no");
        int courseId=getParaToInt("courseId");
        String sql="select * from paperconfig where exam_no=? and course_id=?";
        PaperConfig pc=PaperConfig.dao.findFirst(sql,exam_no,courseId);
        if(pc.set("exam_time",time).update()){
            renderText("修改成功");
        }else{
            renderText("修改失败");
        }
    }

    /**
    *@Author:HeXun
    *@Description: 删除所有考试信息，即将所有考试时间设为0
    *@Date: 2017/8/1 0001
    */
    public void deleteAllExam(){
        if(Db.update("update paperconfig set exam_time=0 where exam_time!=0")>0){
            renderText("清除成功");
        }else{
            renderText("清除失败");
        }
    }
}
